// -----------------------------------------------------------------------
//  <copyright file="UserLoggedOutDomainEvent.cs" company="LiuliuSoft">
//      Copyright (c) 2022-2025 DaprPlus. All rights reserved.
//  </copyright>
//  <site>https://dapr.plus</site>
//  <last-editor>郭明锋</last-editor>
//  <last-date>2025/1/9 12:51</last-date>
// -----------------------------------------------------------------------

using DaprPlus.Domain.Events;
using DaprPlus.Identity.Domain.Entities;


namespace DaprPlus.Identity.Application.Identity.Users.Events;

public record UserLoggedOutDomainEvent : DomainEvent
{
    public long UserId { get; set; }
}

public class SetLogoutTimeHandler(IServiceProvider provider)
    : DomainEventHandlerBase<UserLoggedOutDomainEvent>(provider)
{
    private readonly IServiceProvider _provider = provider;

    protected override async Task OnHandle(UserLoggedOutDomainEvent @event, CancellationToken token)
    {
        var repository = _provider.GetRepository<User>();
        var user = await repository.FindAsync(@event.UserId, token);
        user?.SetLogoutLog(DateTime.Now);
    }
}
